<?php
session_start();
//登录
if(!isset($_POST['submit'])){
    exit('非法访问!');
}
$username = htmlspecialchars($_POST['username']);
$password = $_POST['passname'];
//连接数据库
$conn = @mysqli_connect("localhost","root","","abcd");
if (!$conn){
    die("连接数据库失败：" . mysqli_error());
}
header("Content-type:text/html;charset=utf-8");
//检测用户名及密码是否正确
$sqli="select uid from user where username='$username' and password='$password'";
$check_query = mysqli_query($conn,$sqli);
if($result = mysqli_fetch_array($check_query)){
    if( $_POST['username']===@$_SESSION['username'])
    {
        echo '您已经登录请不要重复登录';
        echo "<a href='zhuxiao.php' style='background-color: aquamarine'>退出登录</a>";
    }
    else {
        $_SESSION['username'] = $username;
        $_SESSION['uid'] = $result['uid'];
        $cengji="select cengji from user where username='$username' and password='$password'";
        $cengji=mysqli_query($conn,$cengji);
        $cengji=mysqli_fetch_array($conn,$cengji);
        $cengji=$cengji[0];
        $_SESSION['cengji']=$cengji;
        //echo $username, ' 欢迎你！进入 <a href="shouye.html">用户中心</a><br />';
        $jifen="select jifen from user where username='$username' and password='$password'";
        $jifen=mysqli_query($conn,$jifen);
        $jifen=mysqli_fetch_row($jifen);
        $jifen=$jifen[0]+1;
        $jifenTwo="update user set jifen=jifen+1 WHERE username='$username'";
        mysqli_query($conn,$jifenTwo);
        echo "<script language='javascript'>alert('登录成功，增加一个积分，您当前的积分为'+$jifen);location.href='shouye.php?&info=$username';</script>";
        //header("Location:jifen.php?url=shouye.php&info=$username");
        exit;
    }
} else {
    exit('登录失败！点击此处 <a href="javascript:history.back(-1);">返回</a> 重试');
}
?>